﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.UI;
using System.IO;
using Bitis_KeToanThue_Pro.AccessDatabase;
using Bitis_KeToanThue_Pro_DungChung.Common;
using Telerik.WinControls.Data;
using System.Reflection;

namespace Bitis_KeToanThue_Pro.Form
{
    public partial class frmChungTuChi : Telerik.WinControls.UI.RadForm
    {
        ChungTuChi ctc = new ChungTuChi();
        private string TienTo = "1112T";
        public frmChungTuChi()
        {
            InitializeComponent();
        }
        private void thietkeluoi()
        {
            //this.grvChungTuChi.EnableHotTracking = true;
            //this.grvChungTuChi.ShowFilteringRow = false;
            //this.grvChungTuChi.EnableFiltering = true;
            //this.grvChungTuChi.MasterTemplate.ShowHeaderCellButtons = true;
            //this.grvChungTuChi.MasterTemplate.ShowFilteringRow = false;
            //this.grvChungTuChi.MasterTemplate.AutoExpandGroups = true;
            ////this.grvChungTuChi.TableElement.RowHeight = 50;
            //this.grvChungTuChi.MasterTemplate.AllowAddNewRow = false;
            //this.grvChungTuChi.MasterTemplate.AutoGenerateColumns = false;
            //this.grvChungTuChi.MasterTemplate.AllowEditRow = true;
            //this.grvChungTuChi.MasterTemplate.AllowDeleteRow = false;
            //this.grvChungTuChi.MasterTemplate.EnableSorting = true;
            //this.grvChungTuChi.MasterTemplate.AllowAutoSizeColumns = true;
            //this.grvChungTuChi.AutoScroll = true;
            //this.grvChungTuChi.EnableAlternatingRowColor = true;

            var columns1 = new GridViewMultiComboBoxColumn();
            columns1.HeaderText = "Cột 1";
            columns1.Width = 130;
            columns1.TextAlignment = ContentAlignment.MiddleRight;
            grvChungTuChi.Columns.Add(columns1);
        }
        private void loadmact()
        {
            RadMultiColumnComboBoxElement multicolumncomboelement = this.multicomboSoCT.MultiColumnComboBoxElement;
            GridViewTextBoxColumn mact = new GridViewTextBoxColumn("MaCT");
            mact.HeaderText = "Mã chứng từ";
            multicolumncomboelement.Columns.Add(mact);

            GridViewTextBoxColumn ngaylap = new GridViewTextBoxColumn("NgayLap");
            ngaylap.HeaderText = "Ngày Lập";
            multicolumncomboelement.Columns.Add(ngaylap);

            GridViewTextBoxColumn nguoilap = new GridViewTextBoxColumn("NguoiLap");
            nguoilap.HeaderText = "Người Lập";
            multicolumncomboelement.Columns.Add(nguoilap);


            multicomboSoCT.DataSource = ctc.loadmact();
            //multicomboSoCT.DisplayMember = "MaCT";
            //multicomboSoCT.ValueMember = "MaCT";
            FilterDescriptor descripter = new FilterDescriptor(multicomboSoCT.DisplayMember, FilterOperator.StartsWith, string.Empty);
            multicomboSoCT.EditorControl.FilterDescriptors.Add(descripter);
            multicomboSoCT.DropDownStyle = RadDropDownStyle.DropDown;
            multicomboSoCT.AutoSizeDropDownHeight = true;
            multicomboSoCT.AutoSizeDropDownToBestFit = true;
        }
        private void loadbophan()
        {
            RadMultiColumnComboBoxElement MultiCombo = this.multicomboBoPhan.MultiColumnComboBoxElement;
            GridViewTextBoxColumn mabp = new GridViewTextBoxColumn("MaDV");
            mabp.HeaderText = "Mã Bộ Phận";
            MultiCombo.Columns.Add(mabp);

            GridViewTextBoxColumn tenbp = new GridViewTextBoxColumn("TenDV");
            tenbp.HeaderText = "Tên Đơn Vị";
            MultiCombo.Columns.Add(tenbp);

            multicomboBoPhan.DataSource = ctc.loadbophan();
            //multicomboBoPhan.DisplayMember = "MaDV";
            //multicomboBoPhan.ValueMember = "MaDV";
            FilterDescriptor descriptor = new FilterDescriptor(this.multicomboBoPhan.DisplayMember, FilterOperator.StartsWith, string.Empty);
            this.multicomboBoPhan.EditorControl.FilterDescriptors.Add(descriptor);
            this.multicomboBoPhan.DropDownStyle = RadDropDownStyle.DropDown;
            this.multicomboBoPhan.AutoSizeDropDownHeight = true;
            this.multicomboBoPhan.AutoSizeDropDownToBestFit = true;
        }
        private void loadtiente()
        {
            RadMultiColumnComboBoxElement MultiCombo1 = this.multicomboLoaiTien.MultiColumnComboBoxElement;
            GridViewTextBoxColumn loaitien = new GridViewTextBoxColumn("Loaitien");
            loaitien.HeaderText = "Loại Tiền";
            MultiCombo1.Columns.Add(loaitien);

            GridViewTextBoxColumn tien = new GridViewTextBoxColumn("Ten");
            tien.HeaderText = "Tên";
            MultiCombo1.Columns.Add(tien);

            multicomboLoaiTien.DataSource = ctc.loadtiente();
            multicomboLoaiTien.DisplayMember = "loaitien";
            multicomboLoaiTien.ValueMember = "loaitien";
            FilterDescriptor discriptor = new FilterDescriptor(multicomboLoaiTien.DisplayMember, FilterOperator.StartsWith, string.Empty);
            multicomboLoaiTien.EditorControl.FilterDescriptors.Add(discriptor);
            multicomboLoaiTien.DropDownStyle = RadDropDownStyle.DropDown;
            multicomboLoaiTien.AutoSizeDropDownHeight = true;
            multicomboLoaiTien.AutoSizeDropDownToBestFit = true;
        }
        private void frmChungTuChi_Load(object sender, EventArgs e)
        {
            txtTK.Text = "1112";
            txtTK.Enabled = false;
            dtpNgayLap.Value = DateTime.Now;
            loadbophan();
            loadmact();
            loadtiente();
            thietkeluoi();
        }

        private void multicomboLoaiTien_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataTable dt = ctc.loadtygia(dtpNgayLap.Value, ClassXuLyChung.GetSafeString(multicomboLoaiTien.SelectedValue));
            if (dt.Rows.Count==0)
            {
                txtTyGia.Text = "";
            }
            else
            {
                txtTyGia.Text = dt.Rows[0][0].ToString();
            }
        }
    }
}
